<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
<h1>发微博页面</h1>
  <input type="text" v-model="weibo.content">
  <input type="button" value="发布" @click="post()">
</div>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<!--引入axios框架文件-->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script>
    let v = new Vue({
        el:"body>div",
        data:{
            weibo:{content:""}
        },
      methods:{
          post(){
            //得到当前登录的用户信息
            let user = localStorage.user?JSON.parse(localStorage.user):null;
            if (user==null){
              location.href="/login.html";
              return;
            }
            //把当前登录的用户id赋值为微博对象
            v.weibo.userId = user.id;
            //发出发微博的请求
            axios.post("/weibo/insert",v.weibo).then(function (response) {
              if (response.data.code==1){
                alert("发布完成!");
                location.href="/";
              }else{
                alert("未登录");
                location.href="/login.html";
              }
            })


          }


      }
    })
</script>
</body>
</html>